//关系：白天连接基站、通信
//用group_geo_id属性存储地理圈id
//构建索引，需要给多种label节点的group_geo_id都设置为索引
CREATE INDEX group_geo_for_user FOR (n:User) ON (n.group_geo_id);
CREATE INDEX group_geo_for_phone FOR (n:Phone) ON (n.group_geo_id);
CREATE INDEX group_geo_for_lac FOR (n:LAC) ON (n.group_geo_id);

//子图构建
CALL gds.graph.drop('famGraph');
MATCH (source:User|Phone)
OPTIONAL MATCH (source)-[r:has|called|day_connect]-(target:Phone|Phone|LAC)
RETURN gds.graph.project(
  'famGraph',
  source,
  target,
  {
    relationshipProperties: r { .weight }
  },
  { undirectedRelationshipTypes: ['*'] }
);

//执行louvain计算并写入属性group_geo_id
CALL gds.louvain.write('famGraph', {
  writeProperty: 'group_geo_id',
  maxLevels:5,
  maxIterations:5,
  relationshipWeightProperty: 'weight'
})
YIELD communityCount, modularity, modularities;


//统计圈节点个数
MATCH (n)
WHERE n.group_geo_id IS NOT NULL
RETURN n.group_geo_id AS group_geo_id, count(n) AS nodeCount
ORDER BY nodeCount DESC

//查看某地理圈
WITH 377 AS comid MATCH (e)-[r]-(e2) WHERE e.group_geo_id = comid AND e2.group_geo_id = comid RETURN *;
